<?php
	/**
	*Author 雷日锦 362606856@qq.com 
	*控制器自动生成
	*/
	if(!defined("ROOT_PATH")) exit("die Access ");
	class shop_flashControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
		}
		
		public function onDefault(){
			$where=" shopid=".SHOPID;
			$url=APPSHOP."?m=shop_flash&a=default";
			$limit=20;
			$start=get("per_page","i");
			$option=array(
				"start"=>0,
				"limit"=>5,
				"order"=>" orderindex ASC,id DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=M("shop_flash")->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			/*
			$empty=max(0,5-count($data));
			for($i=0;$i<$empty;$i++){
				$sdata['orderindex']=$i+count($data);
				$sdata["shopid"]=SHOPID;
				$sdata["status"]=0;
				M("shop_flash")->insert($sdata);
			}
			$data=M("shop_flash")->select($option,$rscount);
			*/
			$this->smarty->assign(
				array(
					"data"=>$data,
					"emptyarr"=>$emptyarr,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url
				)
			);
			$this->smarty->display("shop_flash/index.html");
		}
		
		public function onAdd(){
			$id=get_post("id","i");
			if($id){
				$data=M("shop_flash")->selectRow(array("where"=>"id={$id}"));
				if($data['shopid']!=SHOPID) $this->goall("你无权限",1);
			}
			$this->smarty->assign(array(
				"data"=>$data
			));
			$this->smarty->display("shop_flash/add.html");
		}
		
		public function onSave(){
			
			$id=get_post("id","i");
			$data["title"]=post("title","h");
			$data["imgurl"]=post("imgurl","h");
			$data["linkurl"]=post("linkurl","h");
			$data["orderindex"]=post("orderindex","i");
			$data["shopid"]=SHOPID;
			$data["status"]=0;

			if($id){
				$row=M("shop_flash")->selectRow(array("where"=>"id={$id}"));
				if($row['shopid']!=SHOPID) $this->goall("你无权限",1);
				M("shop_flash")->update($data,"id='$id'");
			}else{
				$id=M("shop_flash")->insert($data);
				$data['id']=$id;
			}
			$this->goall("保存成功",1,$data);
		}
		
		public function onStatus(){
			$id=get_post('id',"i");
			$status=get_post("status","i");
			M("shop_flash")->update(array("status"=>$status),"id=$id");
			$this->sexit(json_encode(array("error"=>0,"message"=>"状态修改成功")));
		}
		
		public function onDelete(){
			$id=get_post('id',"i");
			M("shop_flash")->delete("id=".$id);
			$this->sexit(json_encode(array("error"=>0,"message"=>"删除成功")));
		}
		
		
	}

?>